<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="/resources/template/template.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:p="http://primefaces.org/ui">


    <ui:define name="content">

        <h:panelGroup >
            <h:form  >
                <p:growl />
                <p:focus id="selectFocus" context="gpSelect" />
                <p:focus id="detailFocus" context="gpDetail" />



                <p:panel header="Manage Medicinal Pack " >
                    <h:panelGrid id ="gpVeda" columns="2" >

                        <h:panelGrid id="gpSelect" columns="1"  >
                            <p:panel >
                                <h:panelGrid id="gpSelectText" >                                  
                                    <p:autoComplete id="lstSelect" value="#{amppController.current}" completeMethod="#{amppController.completeAmpp}" 
                                                    forceSelection="true" var="i" itemLabel="#{i.name}" itemValue="#{i}">
                                        <f:ajax event="itemSelect" execute="@this" render="gpDetail"/>
                                    </p:autoComplete>
                                </h:panelGrid>
                                <h:panelGrid id="gpSelectButtons" columns="3"  >
                                    <h:commandButton id="btnAdd" value="Add" action="#{amppController.prepareAdd()}" styleClass="buttons" >

                                    </h:commandButton>
                                    <h:commandButton id="btnDelete" onclick="if (!confirm('Are you sure you want to delete this record?'))
                                                return false;" action="#{amppController.delete()}"  value="Delete"  >
                                    </h:commandButton>
                                </h:panelGrid>
                            </p:panel>
                        </h:panelGrid  >

                        <p:panel>
                            <h:panelGrid id="gpDetail" columns="1">
                                <h:panelGrid id="gpDetailText" columns="2">
                                    <h:outputText id="lblName" value="Pack Name" ></h:outputText>
                                    <h:inputText autocomplete="off" id="txtName" value="#{amppController.current.name}"  ></h:inputText>
                                    <h:outputText  value="Select AMP" ></h:outputText>
                                    <p:autoComplete  converter="ampCon" completeMethod="#{ampController.completeAmp}" 
                                                     var="pta" itemLabel="#{pta.name}" itemValue="#{pta}" forceSelection="true" value="#{amppController.current.amp}" ></p:autoComplete>
                                    <h:outputText  value="Size" ></h:outputText>
                                    <h:inputText autocomplete="off" value="#{amppController.current.dblValue}"  ></h:inputText>
                                    <h:outputText  value="Pack Unit" ></h:outputText>
                                    <p:selectOneMenu value="#{amppController.packUnit}" >
                                        <f:selectItem itemLabel="Select pack"/>
                                        <f:selectItems value="#{measurementUnitController.items}" var="s" itemLabel="#{s.name}" itemValue="#{s}" ></f:selectItems>
                                    </p:selectOneMenu>
                                </h:panelGrid>
                                <h:panelGrid id="gpDetailButtons" columns="2">
                                    <h:commandButton id="btnSave" value="Save" action="#{amppController.saveSelected()}" styleClass="buttons">
                                        <f:ajax render="btnAdd  btnDelete btnSave   lstSelect gpDetail selectFocus"  execute="gpDetail" >
                                        </f:ajax>
                                    </h:commandButton>
                                    <p:defaultCommand target="btnSave"/>
                                </h:panelGrid>
                            </h:panelGrid>
                        </p:panel>
                    </h:panelGrid>
                </p:panel>
            </h:form>

        </h:panelGroup>

    </ui:define>

</ui:composition>
